package tihi.com.horizotalscrolldemo;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import tihi.com.horizotalscrolldemo.base.AbsListItem;


/**
 * Created by tihi on 2017/5/15.
 */

public class HorGridItem extends AbsListItem {

    private HorData data;

    public HorGridItem(Context context, HorData data) {
        super(context);
        this.data = data;
    }

    public HorData getData() {
        return data;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder vh;
        if(convertView == null) {
            vh = new ViewHolder();
            convertView = inflater.inflate(R.layout.hor_gridview_item, null);
            vh.textView = (TextView) convertView.findViewById(R.id.textView);
            convertView.setTag(vh);
        }else {
            vh = (ViewHolder) convertView.getTag();
        }
        updateView(vh);
        return convertView;
    }

    private void updateView(ViewHolder vh) {
        vh.textView.setText(data.getName());
    }

    class ViewHolder{
        private TextView textView;
    }
}
